package com.leetcode.algorithm.y22.m07.w3;

/**
 * 1886. 判断矩阵经轮转后是否一致
 * 
 * https://leetcode.cn/problems/determine-whether-matrix-can-be-obtained-by-rotation/
 * 
 * @author jie.deng
 *
 */
class Question1886Solution01 {

	public boolean findRotation(int[][] mat, int[][] target) {
		int len = mat.length;
		// 轮转0次
		boolean flag = true;
		outer: for (int i = 0; i < len; i++) {
			for (int j = 0; j < len; j++) {
				if (mat[i][j] != target[i][j]) {
					flag = false;
					break outer;
				}
			}
		}
		if (flag) {
			return true;
		}

		// 轮转1次
		flag = true;
		outer: for (int i = 0; i < len; i++) {
			for (int j = 0; j < len; j++) {
				if (mat[i][j] != target[j][len - 1 - i]) {
					flag = false;
					break outer;
				}
			}
		}
		if (flag) {
			return true;
		}

		// 轮转2次
		flag = true;
		outer: for (int i = 0; i < len; i++) {
			for (int j = 0; j < len; j++) {
				if (mat[i][j] != target[len - 1 - i][len - 1 - j]) {
					flag = false;
					break outer;
				}
			}
		}
		if (flag) {
			return true;
		}
		
		// 轮转3次
		flag = true;
		outer: for (int i = 0; i < len; i++) {
			for (int j = 0; j < len; j++) {
				if (mat[i][j] != target[len - 1 - i][j]) {
					flag = false;
					break outer;
				}
			}
		}
		if (flag) {
			return true;
		}		

		return false;
	}

}